import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
import { CategoryService } from '../services/category.service';
import { CreateGoodCategoryDto } from '../dto/create_category.dto';
import { Public } from '@/modules/core/decorators/publicGuards';

@Controller('category')
export class CategoryController {
  constructor(private readonly categoryService: CategoryService) {}
  @Get('list')
  @Public()
  async list() {
    return await this.categoryService.list();
  }

  @Post('create')
  async create(@Body() body: CreateGoodCategoryDto) {
    return await this.categoryService.create(body);
  }

  @Post('update/:id')
  async update(@Param('id') id: string, @Body() body: CreateGoodCategoryDto) {
    return await this.categoryService.update(id, body);
  }

  @Delete('delete/:id')
  async delete(@Param('id') id: string) {
    const res = await this.categoryService.delete(id);
    if (res) {
      return {
        statusCode: 200,
        message: '删除成功',
      };
    }
    return {
      statusCode: 500,
      message: '删除分类失败',
    };
  }
}
